package com.example.service;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.ObjectUtil;
import com.example.common.Constants;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Avatar;
import com.example.exception.CustomException;
import com.example.mapper.AvatarMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务层方法
 */
@Service
public class AvatarService {

    @Resource
    private AvatarMapper avatarMapper;

    public void add(Avatar avatar) {
        avatar.setCreateTime(String.valueOf(DateTime.now()));
        avatarMapper.insert(avatar);
    }

    public void updateById(Avatar avatar) {
        avatarMapper.updateById(avatar);
    }

    public void deleteById(Integer id) {
        avatarMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            avatarMapper.deleteById(id);
        }
    }

    public Avatar selectById(Integer id) {
        return avatarMapper.selectById(id);
    }

    public List<Avatar> selectAll(Avatar avatar) {
        return avatarMapper.selectAll(avatar);
    }

    public PageInfo<Avatar> selectPage(Avatar avatar, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Avatar> list = avatarMapper.selectAll(avatar);
        return PageInfo.of(list);
    }
}
